package com.scs.application.modules.sys.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.scs.application.core.mvc.controller.CrudController;
import com.scs.application.core.query.QueryContext;
import com.scs.application.core.query.QueryContextHolder;
import com.scs.application.modules.dept.entity.ApplyAuto;
import com.scs.application.modules.sys.entity.FlowExecution;
import com.scs.application.modules.sys.model.RestResult;
import com.scs.application.modules.sys.service.FlowExecutionService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 */
@RestController
@RequestMapping("/sys/flow_execution")
public class FlowExecutionController extends CrudController<FlowExecutionService, FlowExecution>{
    //通过业务类型分组
    @GetMapping("/getByBusTypeName")
    public RestResult<List> getByBusTypeName() {
        QueryContext queryContext = QueryContextHolder.currentContext();
        QueryWrapper queryWrapper = Wrappers.<ApplyAuto>query();
        queryWrapper.select("bus_type_name as value,bus_type_name as label");
        queryWrapper.groupBy("bus_type_name");

        List<Map<String, Object>> list = service.listMaps(queryWrapper );
        return RestResult.ok("查询成功", list);
    }

    //通过流程名称分组
    @GetMapping("/getByFlowName")
    public RestResult<List> getByFlowName() {
        QueryContext queryContext = QueryContextHolder.currentContext();

        QueryWrapper queryWrapper = Wrappers.<ApplyAuto>query();
        queryWrapper.select("flow_name as value,flow_name as label");
        queryWrapper.groupBy("flow_name");

        List<Map<String, Object>> list = service.listMaps(queryWrapper );
        return RestResult.ok("查询成功", list);
    }
    //通过流程名称分组
    @GetMapping("/getByFlowStatusText")
    public RestResult<List> getByFlowStatusText() {
        QueryContext queryContext = QueryContextHolder.currentContext();

        QueryWrapper queryWrapper = Wrappers.<ApplyAuto>query();
        queryWrapper.select("flow_status_text as value,flow_status_text as label");
        queryWrapper.groupBy("flow_status_text");

        List<Map<String, Object>> list = service.listMaps(queryWrapper );
        return RestResult.ok("查询成功", list);
    }
}
